package bll

import (
	"context"
	"manager/auth"
	"manager/event"
	"manager/model"
	"manager/store"
	"manager/store/postgres"
)

type cyclingStatics struct {
	iCyclingRecode  store.ICyclingRecode
	iCyclingStatics store.ITrackStatics
}

var CyclingStatics = &cyclingStatics{
	iCyclingRecode:  postgres.CyclingRecode,
	iCyclingStatics: postgres.RouteList,
}

func (a *cyclingStatics) init() func() {
	return func() {}
}

func (a *cyclingStatics) onEvent(*event.Data) {}

// GetUserCyclingData 获取用户骑行记录
func (a *cyclingStatics) GetUserCyclingData(ctx context.Context, req *model.CyclingStaticsReq) (rsp *model.CyclingStaticsRsp, err error) {
	// 用户ID
	userId, _ := auth.ContextUserID(ctx)
	if os := auth.ContextOs(ctx); os != "web" {
		req.UserId = userId
	}

	// 查询统计
	rsp, err = a.iCyclingStatics.TrackStatics(ctx, req)
	return
}
